#include "display.h"

const uint8_t display_host[2][2][8] = {
  {{0xfe, 0xff, 0xab, 0xab, 0xab, 0xab, 0xff, 0xff}, {0xff, 0xff, 0xff, 0xd9, 0xe9, 0xff, 0xff, 0x7f}},
  //{{0xfe, 0x01, 0x55, 0x55, 0x55, 0x55, 0x01, 0xfe}, {0x7f, 0x80, 0x80, 0xa6, 0x96, 0x80, 0x80, 0x7f}}
  {{0xaa, 0x01, 0x54, 0x55, 0x54, 0x55, 0x00, 0x55}, {0xaa, 0x00, 0x80, 0x26, 0x92, 0x00, 0x80, 0x55}}
};

const uint8_t monitor[12] = {0x3e, 0x41, 0x41, 0x45, 0x55, 0xd1, 0xd1, 0x55, 0x45, 0x41, 0x41, 0x3e};
const uint8_t keyboard[12] = {0x78, 0xd4, 0xac, 0xd4, 0xac, 0xd4, 0xac, 0xd4, 0xac, 0xd4, 0xac, 0x78};

void display_geth(uint8_t n, uint8_t *pc)
{
  if(n>3 || n==0)return;
  uint8_t h = switch_get_input();
  uint8_t v = switch_get_output()>>4;
  h = h&(1<<(n-1)) ? 0 : 1;
  for(uint8_t i=0;i<8;i++)
  {
    *pc++ = display_host[h][0][i];
  }
  *pc++ = 0;
  for(uint8_t i=0;i<12;i++)
  {
    *pc++ = v==n ? monitor[i] : 0;
  }
}

void display_getl(uint8_t n, uint8_t *pc)
{
  if(n>3 || n==0)return;
  uint8_t h = switch_get_input();
  uint8_t k = switch_get_output();
  uint8_t v = k>>4;
  k &= 0x0f;
  h = h&(1<<(n-1)) ? 0 : 1;
  for(uint8_t i=0;i<8;i++)
  {
    *pc++ = display_host[h][1][i];
  }
  *pc++ = 0;
  for(uint8_t i=0;i<12;i++)
  {
    *pc++ = k==n ? keyboard[i] : 0;
    if(v==n && i>2 && i<9)
    {
      *(pc-1) |= 0x01;
    }
  }  
}